package com.gitee.ting723.example.controller;

import com.gitee.ting723.upload.service.ImageService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * image controller
 */
@RequestMapping("image")
@RestController
public class ImageUploadController {

    @Resource
    private ImageService imageService;

    @RequestMapping("upload")
    public Map<String, Object> upload(@RequestParam(value = "file") MultipartFile file) {
        String imgUrl = imageService.saveImage(file);
        Map<String, Object> result = new HashMap<>();
        result.put("url", imgUrl);
        result.put("code", 0);
        return result;
    }
}
